package com.j.lemon.learn.flink.datastream;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.api.java.tuple.Tuple1;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.windowing.assigners.TumblingProcessingTimeWindows;
import org.apache.flink.streaming.api.windowing.time.Time;

/**
 * 窗口函数
 * @author lijunjun
 */
public class WindowAllOperator {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        DataStream<Tuple1<Integer>> dataStream = env.socketTextStream("127.0.0.1",8888)
                .map(new MapFunction<String, Tuple1<Integer>>() {
                    @Override
                    public Tuple1<Integer> map(String s) throws Exception {
                        return new Tuple1<>(1);
                    }
                })
        .windowAll(TumblingProcessingTimeWindows.of(Time.seconds(2))).sum(0);
        dataStream.print();

        env.execute();


    }
}
